home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2009 December / maximum-cd-2009-12.iso / DiscContents / gimp-2.7.0-i686-setup.exe / {app} / share / gimp / 2.0 / scripts / select-to-image.scm < prev    next >
Encoding:
GIMP Script-Fu Script  |  2009-08-19  |  2.9 KB  |  89 lines

  1. ; GIMP - The GNU Image Manipulation Program
  2. ; Copyright (C) 1995 Spencer Kimball and Peter Mattis
  3. ;
  4. ; Selection to Image
  5. ; Copyright (c) 1997 Adrian Likins
  6. ; aklikins@eos.ncsu.edu
  7. ;
  8. ; Takes the Current selection and saves it as a seperate image.
  9. ;
  10. ;
  11. ; This program is free software: you can redistribute it and/or modify
  12. ; it under the terms of the GNU General Public License as published by
  13. ; the Free Software Foundation; either version 3 of the License, or
  14. ; (at your option) any later version.
  15. ;
  16. ; This program is distributed in the hope that it will be useful,
  17. ; but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  19. ; GNU General Public License for more details.
  20. ;
  21. ; You should have received a copy of the GNU General Public License
  22. ; along with this program.  If not, see <http://www.gnu.org/licenses/>.
  23.  
  24.  
  25. (define (script-fu-selection-to-image image drawable)
  26.   (let* (
  27.         (draw-type (car (gimp-drawable-type-with-alpha drawable)))
  28.         (image-type (car (gimp-image-base-type image)))
  29.         (selection-bounds (gimp-selection-bounds image))
  30.         (select-offset-x (cadr selection-bounds))
  31.         (select-offset-y (caddr selection-bounds))
  32.         (selection-width (- (cadr (cddr selection-bounds)) select-offset-x))
  33.         (selection-height (- (caddr (cddr selection-bounds)) select-offset-y))
  34.         (active-selection 0)
  35.         (from-selection 0)
  36.         (new-image 0)
  37.         (new-draw 0)
  38.         )
  39.  
  40.     (gimp-context-push)
  41.  
  42.     (gimp-image-undo-disable image)
  43.  
  44.     (if (= (car (gimp-selection-is-empty image)) TRUE)
  45.         (begin
  46.           (gimp-selection-layer-alpha drawable)
  47.           (set! active-selection (car (gimp-selection-save image)))
  48.           (set! from-selection FALSE)
  49.         )
  50.         (begin
  51.           (set! from-selection TRUE)
  52.           (set! active-selection (car (gimp-selection-save image)))
  53.         )
  54.     )
  55.  
  56.     (gimp-edit-copy drawable)
  57.  
  58.     (set! new-image (car (gimp-image-new selection-width
  59.                                          selection-height image-type)))
  60.     (set! new-draw (car (gimp-layer-new new-image
  61.                                         selection-width selection-height
  62.                                         draw-type "Selection" 100 NORMAL-MODE)))
  63.     (gimp-image-add-layer new-image new-draw 0)
  64.     (gimp-drawable-fill new-draw BACKGROUND-FILL)
  65.  
  66.     (let ((floating-sel (car (gimp-edit-paste new-draw FALSE))))
  67.       (gimp-floating-sel-anchor floating-sel)
  68.     )
  69.  
  70.     (gimp-image-undo-enable image)
  71.     (gimp-image-set-active-layer image drawable)
  72.     (gimp-display-new new-image)
  73.     (gimp-displays-flush)
  74.  
  75.     (gimp-context-pop)
  76.   )
  77. )
  78.  
  79. (script-fu-register "script-fu-selection-to-image"
  80.   _"To _Image"
  81.   _"Convert a selection to an image"
  82.   "Adrian Likins <adrian@gimp.org>"
  83.   "Adrian Likins"
  84.   "10/07/97"
  85.   "RGB* GRAY*"
  86.   SF-IMAGE "Image"       0
  87.   SF-DRAWABLE "Drawable" 0
  88. )
  89.